<template>
  <div>
    <header>
      <div>
        <span @click="Return" class="jiantou"></span>
        <p>重置密码</p>
      </div>
    </header>
    <main>
      <div class="separatrix"></div>
      <div class="zhanghao">
        <input type="text" placeholder="账号" v-model="zhanghao" />
      </div>
      <div class="zhanghao">
        <input type="text" placeholder="旧密码" v-model="mima" />
      </div>
      <div class="zhanghao">
        <input type="text" placeholder="请再次输入密码" v-model="xinmima" />
      </div>
      <div class="zhanghao">
        <input type="text" placeholder="请确认密码" v-model="quemima" />
      </div>
      <div class="zhanghao tee">
        <input
          class="yzm"
          type="text"
          placeholder="验证码"
          v-model="yanzhengma"
        />
        <img :src="src" alt="" />
        <p class="te" @click="huan">
          <span>看不清</span>
          <span class="lan">换一张</span>
        </p>
      </div>
      <button @click="RevisePsd">确认修改</button>
      <van-popup v-model="show">{{ text }}</van-popup>
    </main>
  </div>
</template>
<style scoped>
.van-popup {
  width: 4rem;
  height: 4rem;
  text-align: center;
  line-height: 4rem;
}
button {
  width: 90%;
  margin-left: 5%;
  height: 1rem;
  text-align: center;
  line-height: 1rem;
  border-radius: 6px;
  margin-top: 0.6rem;
  color: #fff;
  background-color: #4cd964;
}
.te {
  width: 1rem;
  margin-left: 0.2rem;
}
.lan {
  color: #3190e8;
}
.tee {
  display: flex;
  align-items: center;
}
.yzm {
  width: 50% !important;
}
.zhanghao {
  width: 100%;
  height: 1rem;
  border-bottom: 1px solid #ddd;
}
.zhanghao input {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding-left: 0.4rem;
  border: 0 solid #000;
}
* {
  margin: 0;
  padding: 0;
  font-size: 0.3rem;
}
header {
  position: fixed;
  z-index: 1990;
  top: 0;
  left: 0;
  width: 100%;
  height: 1rem;
  background-color: #3190e8;
}
header div {
  padding-left: 0.2rem;
  padding-right: 0.2rem;
  font-size: 0.3rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 60%;
  height: 1rem;
  color: #fff;
  box-sizing: border-box;
  font-weight: 700;
}
.jiantou {
  width: 0.24rem;
  height: 0.24rem;
  fill: #fff;
  border: 1px solid #fff;
  border-width: 0.06rem 0.06rem 0px 0px;
  transform: rotateZ(225deg);
}
main {
  margin-top: 1rem;
}
.separatrix {
  height: 0.3rem;
  width: 100%;
  background-color: #f5f5f5;
}
</style>
<script>
import Vue from "vue";
import { Popup } from "vant";

Vue.use(Popup);
import { yanzheng, denglu } from "../../api/index.js";
export default {
  data() {
    return {
      arr: [],
      src: "",
      zhanghao: "",
      mima: "",
      xinmima: "",
      quemima: "",
      yanzhengma: "",
      obj: {},
      arrNew: [],
      show: false,
      text: "密码修改成功",
    };
  },
  methods: {
    /* 返回 */
    Return() {
      this.$router.go(-1);
    },
    /* 换验证图片 */
    async huan() {
      var regg = await yanzheng();
      if (regg.data) {
        this.src = regg.data.code;
        // console.log(regg);
      }
    },
    /* 确认修改密码 */
    async RevisePsd() {
      var regg = await denglu({
        captcha_code: this.yanzhengma,
        oldpassWord: this.xinmima,
        username: this.zhanghao,
        confirmpassword: this.xinmima,
        newpassword: this.xinmima,
      });
      if (regg.data) {
        this.arrNew = regg.data;
        console.log(this.arrNew);
        this.text = this.arrNew.success;
        if (this.arrNew.success == "密码修改成功") {
          this.show = true;
        } else {
          var res = await yanzheng();
          this.show = true;
          if (res.data) {
            this.src = res.data.code;
          }
        }
      }
    },
  },
  async mounted() {
    var res = await yanzheng();
    if (res.data) {
      this.src = res.data.code;
      //   console.log(this.src);
    }
  },
};
</script>
